// const { default: axios } = require("axios")

var tbody = document.querySelector('table tbody')

var page = 1
var count = 3
axios.get('/user/home' , {params:{page : page , count : count }}).then((res) => {
    render(res.data.list)
})

function render (data){
    tbody.innerHTML = ''
    data.map((item) => {
        tbody.innerHTML += 
            `<tr>
                <td>${item.email}</td>
                <td>${item.name}</td>
                <td>${item.phone}</td>
                <td>${item.ingroup}</td>
                <td>${item.isadmin ? '是' : '否'}</td>
                <td>${item.status ? '健康' : '变态'}</td>
                <td>编辑 删除</td>
            </tr>`
    })
}
var last =document.querySelector('main .right h4 .last')
var next =document.querySelector('h4 .next')
console.log(last,next);
last.onclick = ()=>{
    if(page > 1){
        page--
        axios.get('/user/home' , {params:{page : page , count : count }}).then((res) => {
            render(res.data.list)
        })

    }
}
next.onclick = ()=> {
    if(page < 4){
        page++
        axios.get('/user/home' , {params:{page : page , count : count }}).then((res) => {
            render(res.data.list)
        })

    }
}

var input = document.querySelector('h2 input')
var button = document.querySelector('h2 button')

button.onclick = ()=>{
    console.log(111);
    axios.get('/user/sousuo' , {params : {text : input.value}} ).then((res) => {
        render(res.data.list)
    })
}